﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AxZWANPHONELib;

namespace TopVisionVideoStream.Mananger
{
    public class VideoCallManager : IDisposable
    {
        public event VideoCallEventHandler VideoCallEvent;

        public VideoCallManager()
        {
            RegistEvent();
        }

        private void OcxApi_ReportMemberStatusEvent(object sender, _DZwanPhoneEvents_ReportMemberStatusEvent e)
        {
            VideoCallEvent?.Invoke(e.lStatus, e.lpCallee);
        }

        private void OcxApi_ConnectedEvent(object sender, _DZwanPhoneEvents_PhoneConnectedEvent e)
        {
            VideoCallEvent?.Invoke(3, "");
        }

        private void OcxApi_SomeOneCallMeEvent(object sender, _DZwanPhoneEvents_SomeOneCallMeEvent e)
        {
            VideoCallEvent?.Invoke(11, e.lpCaller);
        }

        private void RegistEvent()
        {
            OcxApi.ConnectedEvent += OcxApi_ConnectedEvent;
            OcxApi.ReportMemberStatusEvent += OcxApi_ReportMemberStatusEvent;
            OcxApi.SomeOneCallMeEvent += OcxApi_SomeOneCallMeEvent;
        }

        private void UnRegistEvent()
        {
            OcxApi.ConnectedEvent -= OcxApi_ConnectedEvent;
            OcxApi.ReportMemberStatusEvent -= OcxApi_ReportMemberStatusEvent;
            OcxApi.SomeOneCallMeEvent -= OcxApi_SomeOneCallMeEvent;
        }

        public bool VideoCallP2P(string callID, int callType = 2)
        {
            return OcxApi.VideoCallP2P(callID, callType);
        }

        public bool AcceptCall(string callID)
        {
            return OcxApi.AcceptCall(callID);
        }

        public bool Hangup()
        {
            return OcxApi.Hangup();
        }

        public void Dispose()
        {
            UnRegistEvent();
        }
    }
}
